package fxy.fxyOffer;

import java.util.concurrent.atomic.AtomicInteger;

public class TestPrintOrder {
	public static void main(String[] args) {
		AtomicInteger atomic = new AtomicInteger();
		Print tPrint = new Print();
		Thread threadA = new ThreadTest("A", 0, tPrint, 10, atomic);
		Thread threadB = new ThreadTest("B", 1, tPrint, 10, atomic);
		Thread threadC = new ThreadTest("C", 2, tPrint, 10, atomic);
		threadA.start();
		threadB.start();
		threadC.start();
	}
}
class ThreadTest extends Thread{
	private String name = "";
	private Integer id = 0;
	private Print tPrint = null;
	private int count = 0;
	AtomicInteger atomic  = null;
	public ThreadTest(String name, Integer id, Print tPrint, int count,
			AtomicInteger atomic) {
		super();
		this.name = name;
		this.id = id;
		this.tPrint = tPrint;
		this.count = count;
		this.atomic = atomic;
	}
	public void run(){
		while(count > 0){
			if(atomic.get() % 3 == id){
				tPrint.printName(name);
				count --;
				atomic.getAndIncrement();
			}
		}
	}
}
/**
 * ��ӡ
 */
class Print{
	void printName(String name){
		System.out.print(name);
	}
}